from collections.abc import Iterable,Iterator
lst =['a',2,3,4]
for k in lst:
    print(k)

print(isinstance(lst, Iterable))         # True
print(isinstance(lst, Iterator))         # False
print(isinstance(iter(lst), Iterator))   # True

class MyList:
    def __iter__(self):
        return self

    def __getitem__(self, item):
        return item

lst = MyList()
print(isinstance(lst, Iterable))         # True
#a = iter(lst)
#print(a)

# iter 会优先调用 __iter__，如果 __iter__ 不存在会去调用 __getitem__
# for m in lst:
#     print(m)


class CompanyIterator(object):
    def __init__(self,list_data):
        self.index = 0
        self.data = list_data
    def __next__(self):
        try:
            result= self.data[self.index]
            self.index +=1
            return result
        except IndexError:
            raise StopIteration

class Company(object):
    def __init__(self,employess):
        self.employess = employess

    def __iter__(self):
        return CompanyIterator(self.employess)


company = Company(["jack","rose","john","mike"])

for emp in company:
    print(emp)